//
//  WDIronSourceManager.m
//  WDPolymerizeSDK
//
//  Created by little People on 2023/6/1.
//
#import <AppLovinSDK/AppLovinSDK.h>
#import "WDIronSourceManager.h"
#import "WDBannerManager.h"
#import "WDNSLog.h"
#import "WDAdStatusManager.h"
#import "WDJsonManager.h"
#import "WDRewardedVideoManager.h"
#import "WDInterstitialManager.h"
#import "WDFirebaseManager.h"
//@import FirebaseAnalytics;
@import Adjust;
@import IronSource;
//#import <AdjustSdk/Adjust.h>
//#import <IronSource/IronSource.h>
//#define USERID @"demoapp"
//#define APPKEY @"8545d445"
@interface WDIronSourceManager ()<ISInitializationDelegate,ISImpressionDataDelegate>

@end
@implementation WDIronSourceManager
static WDIronSourceManager *_ironSource = nil;
+ (instancetype)shareIronSourceManager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _ironSource = [[self alloc] init];
        
    });
    return _ironSource;
}

- (void)initIronSource
{
    if([WDNSLog logEnable]){
 
    }
    ALSdkInitializationConfiguration *initConfig = [ALSdkInitializationConfiguration configurationWithSdkKey: [WDJsonManager maxKeyForSDKConfigFile] builderBlock:^(ALSdkInitializationConfigurationBuilder *builder) {
        builder.mediationProvider = ALMediationProviderMAX;
      }];

      // Initialize the SDK with the configuration
      [[ALSdk shared] initializeWithConfiguration: initConfig completionHandler:^(ALSdkConfiguration *sdkConfig) {
        // Start loading ads
      }];
    [self initializationDidComplete];

}

- (void)initializationDidComplete {

    [[WDRewardedVideoManager shareRewardedVideoManager] irDelegate];
    [[WDInterstitialManager shareInterstitialManager] interstitialDelegate];
    [[WDBannerManager shareBannerManager] setBannerDelegate];
 
}


- (void)impressionDataDidSucceed:(ISImpressionData *)impressionData {
    
//    [[WDFirebaseManager shareFirebaseManager] ISTaichiFIREvent:impressionData];
//    [@"rewarded_video" ],
    
//激励视频单独计算收入
    
    if ([impressionData.ad_unit isEqualToString:@"rewarded_video"]) {
        return;
    }
    
    

    NSNumber *revenue =[NSNumber numberWithDouble: impressionData.revenue.doubleValue*1000];
    NSString *ad_network = impressionData.ad_network;
    NSDictionary *all_data = impressionData.all_data;
    [[WDAdStatusManager shareStatusManager] adRevenue:impressionData.ad_unit source:impressionData.ad_network revenue:revenue currency:@"USD"];
    WDLog(@"impressionDataDidSucceed revenue:%@,ad_network:%@,all_data:%@",revenue,ad_network,all_data);
    
    ADJAdRevenue *adjustAdRevenue = [[ADJAdRevenue alloc] initWithSource:ADJAdRevenueSourceIronSource];
    [adjustAdRevenue setRevenue:[impressionData.revenue doubleValue] currency:@"USD"];
        // optional fields
    [adjustAdRevenue setAdRevenueNetwork:impressionData.ad_network];
    [adjustAdRevenue setAdRevenueUnit:impressionData.ad_unit];
    [adjustAdRevenue setAdRevenuePlacement:impressionData.placement];
    // track Adjust ad revenue
    [Adjust trackAdRevenue:adjustAdRevenue];
}



@end
